package com.bykj.property.api.controller;

import com.bykj.property.service.ChargeStandardService;
import com.bykj.property.model.ChargeStandard;
import com.bykj.property.config.common.exception.CustomException;
import com.bykj.property.controller.vo.response.ErrorCode;
import com.bykj.property.controller.vo.response.RespResult;
import com.bykj.property.controller.vo.request.ChargeStandardPageRequest;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import javax.servlet.http.HttpServletRequest;
import org.springframework.validation.BindingResult;

import javax.validation.ValidationException;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import com.alibaba.fastjson.JSON;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import javax.validation.constraints.NotEmpty;

    import org.springframework.web.bind.annotation.RestController;

/**
* <p>
    * 收费标准表 前端控制器
    * </p>
*
* @author liangyiming
* @since 2019-07-02
*/

@Slf4j
    @Api(tags = {"收费标准表"})
    @RestController
   @RequestMapping("/api/ChargeStandard")
        public class ChargeStandardApiController {
    @Autowired
    ChargeStandardService targetService;

    @ApiOperation(value="添加")
    @RequestMapping(value = "/add",method = RequestMethod.POST,produces = "application/json;charset=UTF-8" )
    public RespResult add(ChargeStandard model, BindingResult bindingResult) {
    return RespResult.ok(targetService.save(model));
    }

    @ApiOperation(value="更新")
    @RequestMapping(value = "/update",method = RequestMethod.POST,produces = "application/json;charset=UTF-8" )
    public RespResult update(ChargeStandard model) {
    return RespResult.ok(targetService.updateById(model));
    }

    @ApiOperation(value="删除接口")
    @RequestMapping(value = "/delete",method = RequestMethod.POST,produces = "application/json;charset=UTF-8" )
    public RespResult delete(@NotEmpty String id) {
    return RespResult.ok(targetService.removeById(id));
    }

    @ApiOperation(value="查询列表接口")
    @RequestMapping(value = "/query",method = RequestMethod.POST,produces = "application/json;charset=UTF-8" )
    public RespResult query(ChargeStandardPageRequest pageRequest, BindingResult bindingResult) {
    if(pageRequest.getSize()==-1){
    return RespResult.ok(targetService.list());
    }
    return RespResult.ok(targetService.queryPage(pageRequest));
    }

    @ApiOperation(value="查询详情接口")
    @ApiImplicitParams({
    @ApiImplicitParam(name="id",value="id",dataType="String", paramType = "query")
    })
    @RequestMapping(value = "/get",method = RequestMethod.POST,produces = "application/json;charset=UTF-8" )
    public RespResult get(@NotEmpty String id) {
    return RespResult.ok(targetService.getById(id));
    }

    }
